package com.tedu.ds.equipmentType.service.impl;

import com.tedu.ds.equipmentType.mapper.EquipmentTypeMapper;
import com.tedu.ds.equipmentType.pojo.dto.EquipmentTypeParam;
import com.tedu.ds.equipmentType.pojo.dto.EquipmentTypeQuery;
import com.tedu.ds.equipmentType.pojo.entity.EquipmentType;
import com.tedu.ds.equipmentType.pojo.vo.EquipmentTypeVO;
import com.tedu.ds.equipmentType.service.EquipmentTypeService;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

@Service
public class EquipmentTypeServiceImpl implements EquipmentTypeService {
    @Autowired
    private EquipmentTypeMapper equipmentTypeMapper;

    @Override
    public List<EquipmentTypeVO> select(EquipmentTypeQuery equipmentTypeQuery) {
        List<EquipmentTypeVO> list=equipmentTypeMapper.select(equipmentTypeQuery);
        return list;
    }

    @Override
    public void save(EquipmentTypeParam equipmentTypeParam) {
        EquipmentType equipmentType=new EquipmentType();
        BeanUtils.copyProperties(equipmentTypeParam,equipmentType);
        if (equipmentType.getId()==null){
            equipmentType.setStatus(10);
            equipmentTypeMapper.insert(equipmentType);
        }else if (equipmentType.getStatus()==40){
            equipmentType.setDeleteTime(new Date());
            equipmentTypeMapper.update(equipmentType);
        }else {
            equipmentTypeMapper.update(equipmentType);
        }
    }

    @Override
    public void delete(Integer id) {
        equipmentTypeMapper.delete(id);
    }
}
